/*
 * 文件名：OrderController.java
 * 版权：Copyright by hlst
 * 描述：
 * 修改人：liuziyu
 * 修改时间：2016年7月25日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package com.zcsy.manage.shop.controller.order;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zcsy.commons.constants.Constants;
import com.zcsy.commons.constants.OwnerConstants;
import com.zcsy.commons.constants.ShopConstants;
import com.zcsy.commons.model.RequestJson;
import com.zcsy.commons.util.DateUtils;
import com.zcsy.manage.model.base.CommonToken;
import com.zcsy.manage.model.mall.OrderDetailInfo;
import com.zcsy.manage.model.mall.OrderInfo;
import com.zcsy.manage.service.mall.IOrderDetailInfoService;
import com.zcsy.manage.service.mall.IOrderInfoService;
import com.zcsy.manage.service.push.impl.PushServiceImpl;
import com.zcsy.manage.shop.service.system.ICommonTokenService;

/**
 * @Title: OrderController.java
 * @Package： com.zcsy.manage.shop.controller.order 
 * @Description: 商户订单控制层
 * @author liuziyu liuziyuwri@foxmail.com
 * @Copyright: 2016 武汉恒数利通软件有限公司 All rights reserved.
 * @date 2016年7月25日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
@Controller
@RequestMapping(value = "/shopOrder")
public class OrderController {
	
	private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

	@Autowired
	IOrderInfoService orderInfoService;
	
	@Autowired
	IOrderDetailInfoService orderDetailInfoService;
	
	@Autowired
	ICommonTokenService commomTokenService;
	
	@Autowired
	PushServiceImpl pushService;
	
	/**
	 * @Method: getAllOrder
	 * @Description 查询所有订单（根据不同订单状态） 
	 * @param pNo 分页
	 * @param shopId 店铺id
	 * @param orderState 订单状态 （ 1待付款， 2待确认， 3待发货， 4退款/售后， 5全部， 6已发货， 7已完成， 8已关闭）
	 * @return 
	 * @author liuziyu liuziyuwri@foxmail.com
	 * @date 2016年7月25日
	 * @see 
	 */
	@RequestMapping(value = "getAllOrder")
	@ResponseBody
	public RequestJson getAllOrder(String shopId, Integer orderState, Integer pNo) {

		RequestJson result = new RequestJson();

		// 指定默认为首页
		if (pNo == null || pNo < ShopConstants.PAGE_NO) {
			pNo = ShopConstants.PAGE_NO;
		}
		

		// 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
		PageHelper.startPage(pNo, ShopConstants.PAGE_SIZE);
        
		// 1待付款
		if (orderState == ShopConstants.ORDERSTATE_NOT_PAY) {
			List<OrderInfo> orderList = orderInfoService.selectByShopIdAndState(shopId,ShopConstants.SQL_ORDERSTATE_NOT_PAY);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取待付款订单成功！");
				result.setObj(orderListP);
				
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无待付款订单！");

			}

			// 2待确认
		} else if (orderState == ShopConstants.ORDERSTATE_NOT_CONFIRM) {
			List<OrderInfo> orderList = orderInfoService.selectByShopIdAndState(shopId,ShopConstants.SQL_ORDERSTATE_NOT_PAY);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取待确认订单成功！");
				result.setObj(orderListP);
				
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无待确认订单！");

			}

			// 3待发货
		} else if (orderState == ShopConstants.ORDERSTATE_NOT_SEND) {
			List<OrderInfo> orderList = orderInfoService.selectByShopIdAndState(shopId,ShopConstants.SQL_ORDERSTATE_NOT_PAY);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取待发货订单成功！");
				result.setObj(orderListP);
				
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无待发货订单！");

			}

			// 4退款/售后
		} else if (orderState == ShopConstants.ORDERSTATE_AFTER_SALE) {
			
			List<OrderInfo> orderList = orderInfoService.selectAfterSaleByShopId(shopId);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取退款/售后订单成功！");
				result.setObj(orderListP);
				
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无退款/售后订单！");

			}

			// 5全部
		} else if (orderState == ShopConstants.ORDERSTATE_ALL) {
			// 查找店铺下的全部订单
			List<OrderInfo> orderList = orderInfoService.selectByShopIdAndState(shopId,ShopConstants.SQL_ORDERSTATE_NOT_PAY);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取全部订单成功！");
				result.setObj(orderListP);
				
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无全部订单！");

			}

			// 6已发货（配送中）
		} else if (orderState == ShopConstants.ORDERSTATE_ALREADY_SEND) {
			List<OrderInfo> orderList = orderInfoService.selectByShopIdAndState(shopId,ShopConstants.SQL_ORDERSTATE_NOT_PAY);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取配送中订单成功！");
				result.setObj(orderListP);
				
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无配送中订单！");

			}

			// 7已完成
		} else if (orderState == ShopConstants.ORDERSTATE_DONE) {
			List<OrderInfo> orderList = orderInfoService.selectByShopIdAndState(shopId,ShopConstants.SQL_ORDERSTATE_NOT_PAY);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取已完成订单成功！");
				result.setObj(orderListP);
				
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无已完成订单！");

			}

			// 8已关闭(已取消)
		} else if (orderState == ShopConstants.ORDERSTATE_CLOSE) {
			List<OrderInfo> orderList = orderInfoService.selectByShopIdAndState(shopId,ShopConstants.SQL_ORDERSTATE_NOT_PAY);
			
			if (CollectionUtils.isNotEmpty(orderList)) {
				Iterator<OrderInfo> iterator = orderList.iterator(); 
				while(iterator.hasNext()){ 
					OrderInfo order = (OrderInfo) iterator.next(); 
					String orderId = order.getId();
					// 根据订单id查询订单里的具体商品
					List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
					order.setOrderDetailList(orderDetails);
				}  
				
				// 分页
		        PageInfo<OrderInfo> orderListP = new PageInfo<OrderInfo>(orderList);
		        
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("获取已取消订单成功！");
				result.setObj(orderListP);
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无已取消订单！");
			}
		} else {
			result.setSuccess(false);
            result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
            result.setMsg("订单状态有误！");
		}
		return result;
	}
	
	/**
     * @Method: getOrderDetail
     * @Description 获取订单详情
     * @param orderId 订单id
     * @return 
     * @author liuziyu liuziyuwri@foxmail.com
     * @date 2016年7月27日
     * @see 
     */
    @RequestMapping(value = "getOrderDetail")
    @ResponseBody
    public RequestJson getOrderDetail(String orderId) {

        RequestJson result = new RequestJson();
        
        // 根据订单id查询订单
        OrderInfo orderInfo = orderInfoService.selectByPrimaryId(orderId);
        
        if (orderInfo != null) {
            // 根据订单id查询订单里的具体商品
            List<OrderDetailInfo> orderDetails = orderDetailInfoService.getGoodsDetailByOrderId(orderId);
            if (!orderDetails.isEmpty()) {
                orderInfo.setOrderDetailList(orderDetails);
                result.setSuccess(true);
                result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
                result.setMsg("获取订单详情成功！");
                result.setObj(orderInfo);
                
            } else {
                result.setSuccess(false);
                result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
                result.setMsg("查询不到订单详情！");

            }
        } else {
            result.setSuccess(false);
            result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
            result.setMsg("订单id有误！");
        }
        return result;
    }
	
	/**
     * @Method: getSearchOrderInfo
     * @Description 根据关键字和状态查询订单信息 
     * @param pNo 分页
     * @param shopId 店铺id
     * @param searchKey 关键字（联系人 ，联系人电话，订单号）
     * @param shopOrderState 订单状态（1待付款，2待确认，3待发货，4退款/售后，5全部，6已发货，7已完成，8已关闭）
     * @return 
     * @author yangfan 373188993@qq.com
     * @date 2016年7月27日
     * @see 
     */
    @RequestMapping(value = "getSearchOrderInfo")
    @ResponseBody
    public RequestJson getSearchOrderInfo(String shopId, Integer shopOrderState, Integer pNo ,String searchKey) {

        RequestJson result = new RequestJson();

        try {
            
            OrderInfo orderInfo = new OrderInfo();
            orderInfo.setShopId(shopId);
            orderInfo.setShopOrderState(shopOrderState);
            orderInfo.setSearchKey(searchKey);
            
            List<OrderInfo> orderInfoList = orderInfoService.getOrderAndGoodsInfo(orderInfo);
            // 指定默认为首页
            if (pNo == null || pNo < ShopConstants.PAGE_NO) {
                pNo = ShopConstants.PAGE_NO;
            }
            
            // 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
            PageHelper.startPage(pNo, ShopConstants.PAGE_SIZE);
            
            //查询所对应的订单用于分页
            List<OrderInfo> orderInfoListForP = orderInfoService.getOrderByKeyWords(orderInfo);
            
            //将对应的订单详情列表放入已分页了的订单列表中（解决订单分页不正确的问题）
            if(!CollectionUtils.isEmpty(orderInfoListForP) && !CollectionUtils.isEmpty(orderInfoList)) {
                for(int i = 0; i<orderInfoListForP.size();i++) {
                    for(int j = 0;j<orderInfoList.size();j++) {
                        if(orderInfoListForP.get(i).getId().equals(orderInfoList.get(j).getId())) {
                            orderInfoListForP.get(i).setOrderDetailList(orderInfoList.get(j).getOrderDetailList());
                        }
                        
                    }
                }
            }
            
            // 分页
            PageInfo<OrderInfo> orderInfoListP = new PageInfo<OrderInfo>(orderInfoListForP);
            result.setSuccess(true);
            result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
            result.setMsg("获取数据成功！");
            result.setObj(orderInfoListP); 
        } catch (Exception e) {
            result.setSuccess(false);
            result.setResultCode(OwnerConstants.RESULT_EXCEPTION_FALSE);
            result.setMsg("网络异常");
        }
        return result;
    }
    
    /**
	 * @Method: changeOrder
	 * @Description 订单操作
	 * @param orderId 订单id
	 * @param token 
	 * @param operationType （1确认订单， 2拒绝订单， 3发货， 4确认退款， 5拒绝退款， 6确认退货， 7拒绝退货）
	 * @return 
	 * @author liuziyu liuziyuwri@foxmail.com
	 * @date 2016年7月27日
	 * @see 
	 */
	@RequestMapping(value = "changeOrder")
	@ResponseBody
	public RequestJson changeOrder(String orderId, Integer operationType, String token) {

		RequestJson result = new RequestJson();
		CommonToken tokenInfo = commomTokenService.selectByToken(token);
		String loginname = tokenInfo.getAccount();

		// 1确认订单
		if (operationType == ShopConstants.ORDER_CONFIRM) {
			// 根据订单id查询订单
			OrderInfo orderInfo = orderInfoService.selectByPrimaryId(orderId);

			if (orderInfo.getDistributionType() != null && orderInfo.getIsBySelf() !=null) {
				// 需要配送且不自提
				if (orderInfo.getDistributionType() == ShopConstants.DISTRIBUTION_NEED
						&& orderInfo.getIsBySelf() == ShopConstants.BYSELF_NO) {
					
					
					// 记录确认时间
					orderInfo.setSureTime(DateUtils.gettimestamp());
					orderInfo.setState(ShopConstants.SQL_ORDERSTATE_NOT_SEND);
					
					int state = orderInfoService.update(orderInfo);
					
					logger.debug("确认订单：" + state + "，1为成功。");
					if (state == ShopConstants.UPDATE_SUCCESS) {
						
						// 推送消息
						String msg = pushService.pushDistributionMsg(orderId, ShopConstants.PUSH_TYPE_ONE);
						System.out.println("确认订单推送结果，订单id：" + orderId + "，返回消息："+ msg);
						
						result.setSuccess(true);
						result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
						result.setMsg("确认成功，等待配送！");
						result.setObj("state="
								+ ShopConstants.SQL_ORDERSTATE_NOT_SEND);
					} else {
						result.setSuccess(false);
						result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
						result.setMsg("操作失败！");

					}
					// 要配送且自提 或 不配送
				} else if ((orderInfo.getDistributionType() == ShopConstants.DISTRIBUTION_NEED && orderInfo
						.getIsBySelf() == ShopConstants.BYSELF_YES)
						|| orderInfo.getDistributionType() == ShopConstants.DISTRIBUTION_NO_NEED) {
					
					// 记录确认时间
					orderInfo.setSureTime(DateUtils.gettimestamp());
					orderInfo.setState(ShopConstants.SQL_WAIT_USE);
					int state = orderInfoService.update(orderInfo);
					
					if (state == ShopConstants.UPDATE_SUCCESS) {
						
						result.setSuccess(true);
						result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
						result.setMsg("确认成功，等待自提！");
						result.setObj("state=" + ShopConstants.SQL_WAIT_USE);
					} else {
						result.setSuccess(false);
						result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
						result.setMsg("操作失败！");
					}
				} else {
					result.setSuccess(false);
					result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
					result.setMsg("此订单的配送状态或自提状态有误！");
				}
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无此订单或配送状态或自提状态填写不全！");
			}
			// 2拒绝订单
		} else if (operationType == ShopConstants.ORDER_REJECT) {
			int state = orderInfoService.updateOrderStateByMap(orderId,ShopConstants.SQL_REFUND_CONFIRMED,loginname);
			
			if (state == ShopConstants.UPDATE_SUCCESS) {
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("拒绝成功！");
				result.setObj("state="
						+ ShopConstants.SQL_REFUND_CONFIRMED);
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("操作失败！");

			}
			// 3发货
		} else if (operationType == ShopConstants.ORDER_SEND) {
			
			// 判断是否有配送员
			OrderInfo orderInfo = orderInfoService.selectOrderByPrimaryKey(orderId);
			
			if (orderInfo != null) {
				
				// 有配送员则发货
			    if (!StringUtils.isEmpty(orderInfo.getSenderAccount())) {
					// 记录发货时间和账号
					orderInfo.setSendTime(DateUtils.gettimestamp());
					orderInfo.setSendAccount(loginname);
					orderInfo.setState(ShopConstants.SQL_ORDERSTATE_SENDING);
					int state = orderInfoService.update(orderInfo);
					
					if (state == ShopConstants.UPDATE_SUCCESS) {
						result.setSuccess(true);
						result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
						result.setMsg("发货成功！");
						result.setObj("state="
								+ ShopConstants.SQL_ORDERSTATE_SENDING);
					} else {
						result.setSuccess(false);
						result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
						result.setMsg("操作失败！");
						
					}
					
				} else {
				    result.setSuccess(false);
                    result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
                    result.setMsg("未分配到配送员无法发货！");
				}
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无此订单！");
			}
			// 4确认退款
		} else if (operationType == ShopConstants.ORDER_CONFIRM_REFUND) {
			
			OrderInfo orderInfo = orderInfoService.selectOrderByPrimaryKey(orderId);
			if (orderInfo != null) {
				
				// 记录确认退款时间和账号
				orderInfo.setRefundConfirmTime(DateUtils.gettimestamp());
				orderInfo.setRefundConfirmAccount(loginname);
				orderInfo.setState(ShopConstants.SQL_REFUND_CONFIRMED);
				int state = orderInfoService.update(orderInfo);
				
				if (state == ShopConstants.UPDATE_SUCCESS) {
					result.setSuccess(true);
					result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
					result.setMsg("确认退款成功！");
					result.setObj("state="
							+ ShopConstants.SQL_REFUND_CONFIRMED);
				} else {
					result.setSuccess(false);
					result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
					result.setMsg("操作失败！");
					
				}
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无此订单！");
			}
			
			// 5拒绝退款
		} else if (operationType == ShopConstants.ORDER_REJECT_REFUND) {
			int state = orderInfoService.updateOrderStateByMap(orderId,ShopConstants.SQL_ORDERSTATE_NOT_CONFIRM,loginname);
			
			if (state == ShopConstants.UPDATE_SUCCESS) {
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("拒绝退款成功！");
				result.setObj("state="
						+ ShopConstants.SQL_ORDERSTATE_NOT_CONFIRM);
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("操作失败！");

			}
			// 6确认退货
		} else if (operationType == ShopConstants.ORDER_CONFIRM_RETURN) {

			OrderInfo orderInfo = orderInfoService
					.selectOrderByPrimaryKey(orderId);

			if (orderInfo != null) {

				// 记录确认退货时间和账号
				orderInfo.setReturnConfirmTime(DateUtils.gettimestamp());
				orderInfo.setReturnConfirmAccount(loginname);
				orderInfo.setState(ShopConstants.SQL_RETURN_CONFIRMED);
				int state = orderInfoService.update(orderInfo);
				
				if (state == ShopConstants.UPDATE_SUCCESS) {
					result.setSuccess(true);
					result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
					result.setMsg("退货成功！");
					result.setObj("state=" + ShopConstants.SQL_RETURN_CONFIRMED);
				} else {
					result.setSuccess(false);
					result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
					result.setMsg("操作失败！");

				}
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("无此订单！");
			}

			// 7拒绝退货
		} else if (operationType == ShopConstants.ORDER_REJECT_RETURN) {
			int state = orderInfoService.updateOrderStateByMap(orderId,ShopConstants.SQL_ORDERSTATE_COMPLETE,loginname);
			
			if (state == ShopConstants.UPDATE_SUCCESS) {
				result.setSuccess(true);
				result.setResultCode(ShopConstants.RESULT_CODE_SUCCESS);
				result.setMsg("拒绝退货成功！");
				result.setObj("state="
						+ ShopConstants.SQL_ORDERSTATE_COMPLETE);
			} else {
				result.setSuccess(false);
				result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
				result.setMsg("操作失败！");

			}
			
		} else {
			result.setSuccess(false);
			result.setResultCode(ShopConstants.RESULT_CODE_FALSE);
			result.setMsg("订单状态有误！");

		}
		return result;
	}
}
